import {createRouter,createWebHashHistory} from "vue-router"

import Home from "../components/Home.vue"
import List from "../components/List.vue"


//创建路由
// let router = createRouter({
//     history:createWebHashHistory(),
//     routes:[
//         {
//             path:"/home",
//             component:Home
//         },
//         {
//             path:"/list",
//             component:List
//         }
//     ]
// })

let router = createRouter({
    history:createWebHashHistory(),
    routes:[
        {
            path:"/home",
            name:"myHome",
            components:{
                HomeView:Home
            }
        },
        {
            path:"/list/:id/:name",
            name:"myList",
            components:{
                ListView:List
            }
        },
        {
            path:"/redirect",
            redirect:"/list"
        }

    ]
})



//前置路由守卫
router.beforeEach((to,from,next)=>{
    console.log(to.path);
    console.log(from.path);

    if(to.path=="/home"){
        console.log("可以在这里登录了");
        
    }
    next();
        
})

//后置路由守卫
router.afterEach((to,from,next)=>{
    console.log("后置路由守卫执行！");
    
})



//导出路由
export default router;